package com.springboot.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.springboot.dao.HistoryMapper;
import com.springboot.entity.History;
import com.springboot.utils.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
@Service
public class HistoryServiceImpl implements HistoryService{
    @Autowired
    private HistoryMapper historyMapper;
    @Override
    public ResultVO historyListZero(int pageNum) {
        long status=1;
        PageHelper.startPage(pageNum,5); //设置分页的页面容量
        Example example=new Example(History.class);
        Example.Criteria criteria=example.createCriteria();
//模糊查询
        if(!StringUtils.isEmpty(status)){
//进行模糊查询
            criteria.andEqualTo("status",status);
        }
        List<History> list = historyMapper.selectByExample(example);
        PageInfo<History> pageInfo=new PageInfo<History>(list);
        return new ResultVO(1005,"查询成功",pageInfo);
    }

    @Override
    public ResultVO saveHistoryZero(History history) {
        int i = historyMapper.updateHistoryZero(history);
        if(i>0){
            return new ResultVO(3000,"修改成功",i);
        }else{
            return new ResultVO(3001,"修改失败",null);
        }
    }

    @Override
    public ResultVO historyLisOne(int pageNum) {
        long status=0;
        PageHelper.startPage(pageNum,5); //设置分页的页面容量
        Example example=new Example(History.class);
        Example.Criteria criteria=example.createCriteria();
//模糊查询
        if(!StringUtils.isEmpty(status)){
//进行模糊查询
            criteria.andEqualTo("status",status);
        }
        List<History> list = historyMapper.selectByExample(example);
        PageInfo<History> pageInfo=new PageInfo<History>(list);
        return new ResultVO(1005,"查询成功",pageInfo);
    }

    @Override
    public ResultVO saveHistoryOne(History history) {
        int i = historyMapper.updateHistoryOne(history);
        if(i>0){
            return new ResultVO(3000,"修改成功",i);
        }else{
            return new ResultVO(3001,"修改失败",null);
        }
    }
}
